<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/list.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/commom.js"></script>
    <style>
        
        .nav{
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 50px;
        }
        .container{
            padding-top: 80px;
            height: auto;
        }
        .container-right{
            width: auto;
        }
        .blog-pagnation-wrapper{
            height: 40px;
            margin: 16px 0;
            text-align: center;
        }
        .blog-pagnation-item{
            display: inline-block;
            padding: 8px;
            border: 1px solid #d0d0d5;
            color: #333;
        }
        .blog-pagnation-item:hover{
            background: #4e4eeb;
            color: #fff;
        }
        .blog-pagnation-item.actvie{
            background: #4e4eeb;
            color: #fff;
        }

    </style>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <!-- <a href="blog_list.html">主页</a> -->
        <a href="/blog/myblog_list.html">个人博客列表页</a>
        <a href="/blog/blog_add.html">写博客</a>
        <a href="/blog/mydraft_list.html">草稿箱</a>
        <a href="/blog/login.html">登陆</a>
        <a href="javascript:logout()">注销</a>
        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <!-- 每一篇博客包含标题, 摘要, 时间 -->
            <div id="artListDiv">
                
            </div>
            <hr>
            <div class="blog-pagnation-wrapper">
                <button onclick="goFirstPage()" class="blog-pagnation-item">首页</button> 
                <button onclick="goBeforePage()" class="blog-pagnation-item">上一页</button>  
                <button onclick="goNextPage()" class="blog-pagnation-item">下一页</button>
                <button onclick="goLastPage()" class="blog-pagnation-item">末页</button>
            </div>
        </div>
    </div>
    <script>
        //当前页码
        var index = 1;
        //每页显示条数
        var psize = 3;
        //最大页码数
        var pcount = 1;
        //1、尝试获取url中的页码
        index = (getUrlValue("index")==""?1:getUrlValue("index"));
        //2、交互
        function initPage() {
            jQuery.ajax({
                url: "/blog/art/listpage",
                type: "POST",
                data: {"index":index,"psize":psize},
                success: function(result) {
                    if(result != null && result.code == 200 && result.data.list.length>0) {
                        var listhtml = "";
                        for(var i = 0;i<result.data.list.length;i++) {
                            var article = result.data.list[i];
                            listhtml += '<div class="blog">';
                                listhtml += '<div class="title">'+article.title+'</div>';
                                listhtml += '<div class="date">'+article.createtime+'</div>';
                                if(article.content.length > 200) {
                                    article.content = article.content.substring(0,200);
                                }
                                listhtml += '<div class="desc">'+article.content+'</div>';
                                listhtml += '<a href="/blog/blog_content.html?id='+article.id+'" class="detail">查看全文 &gt;&gt;</a>';
                            listhtml += '</div>';
                        }
                        jQuery("#artListDiv").html(listhtml);
                        pcount = result.data.sizeLast;
                    }
                }
            });
        }
        initPage();
        
        //跳转首页
        function goFirstPage() {
            if(index <= 1) {
                alert("当前已经在首页了");
                return;
            }
            location.href = "/blog/blog_list.html";
        }
        //跳转下一页
        function goNextPage() {
            if(index >= pcount) {
                alert("当前已经在末页了");
                return;
            }
            index++;
            location.href = "/blog/blog_list.html?index="+index;
        }
        //跳转上一页
        function goBeforePage() {
            if(index <= 1) {
                alert("当前已经在首页了");
                return;
            }
            index--;
            location.href = "/blog/blog_list.html?index=" + index;
        }
        //跳转末页
        function goLastPage() {
            if(index >= pcount) {
                alert("当前已经在末页了");
                return;
            }
            location.href = "/blog/blog_list.html?index="+pcount;
        }

    </script>
</body>
</html>